﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Shared/Shared.master" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="OpenPhotoAlbum.Shared.Home" %>
<%@ Register Assembly="OpenPhotoAlbum" Namespace="OpenPhotoAlbum.Controls" TagPrefix="cc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ph1" runat="server">
<script language="javascript" type="text/javascript">
	Sys.Application.add_load(onLoad);
	function onLoad() { loadAlbums(); }
	function loadAlbums() {
		var userId = '<%= OpenPhotoAlbum.UrlContext.UserId %>';
		if (!userId) { return; }
		OpenPhotoAlbum.Shared.Albums.GetAlbums(userId, 1, false, onSuccess, onFailed, null);
		$get('albums').innerHTML = '<%= Resources.Strings.Shared_LoadingAlbums %>';
	}
	function onSuccess(result, context) {
		var albums = [];
		if (result) { albums = Sys.Serialization.JavaScriptSerializer.deserialize(result); }
		var html = new Sys.StringBuilder();
		for (var i in albums) {
			var album = albums[i];
			html.append('<table class="item"><tr><td>');
			html.append(String.format(
				'<a href="{0}" class="thumbnail"><img src="{1}" /></a>',
				album.SharedAlbumUrl,
				album.PhotoPipeUrl));
			html.append(String.format('<span class="albumTitle">{0}</span>', album.Title));
			html.append(String.format('<span class="description">{0}</span>', album.Description));
			html.append(String.format('<span class="creationDate">{0}</span>', album.CreationDate));
			html.append(String.format('<span class="modificationDate">{0}</span>', album.ModificationDate));
			html.append(String.format('<span class="photoCount">{0}</span>', album.PhotoCount));
			html.append('</td></tr></table>');
		}
		$('#albums').css('visibility', 'hidden');
		$('#albums').html(html.toString()); adjust();
		$('#albums').css('visibility', 'visible');
	}
	function onFailed(e) {}
	function adjust() {
		if (jQuery.browser.safari) {
			$('table.item').each(function() { $(this).css('display', 'inline-table'); });
		}
		else if (jQuery.browser.mozilla) {
			$('table.item').each(function() { $(this).css('display', 'inline-block'); });
		}
	};
</script>
<div class="home"><div id="albums" class="albums" ></div></div>
</asp:Content>
